import { _decorator, Component, Label, Node } from 'cc';
import { ETalent, Talent, TalentData } from '../core/Talent';
import { Core } from '../core/Core';
import { EGameEvent } from '../core/Config';
const { ccclass, property } = _decorator;
/**
 * 天赋节点
 */
@ccclass('TalentItem')
export class TalentItem extends Component {


    @property(Node)
    icon: Node;
    @property(Node)
    lableName: Node;
    @property(Node)
    lableDesc: Node;

    private _talent: Talent;


    start() {

    }

    update(deltaTime: number) {

    }
    init(talent: Talent) {
        this._talent = talent;
        if(!talent){
            return;
        }
        this.lableName.getComponent(Label).string = talent.getData().name;
        this.lableDesc.getComponent(Label).string = talent.getData().desc + `等级${talent.level + 1}`;
    }

    private onButtonClick() {

        if (!this._talent) {
            return;
        }
        const price=(this._talent.level + 1) * 100;
        if(Core.instance.playerData.gold < price){
            console.log("金币不足");
            return;
        }
        this._talent.level ++;
        Core.instance.playerData.gold -= price;
        Core.instance.event.emit(EGameEvent.SAVE);
        Core.instance.event.emit(EGameEvent.PLAYER_DATA_CHANGED);

    }
}


